class PetShop {
    private String shopName; // 商店名称
    private Pet[] cages; // 宠物笼子，用数组存储宠物
    private int currentIndex; // 用于记录当前笼子中宠物的数量
    private Pet[] soldPets; // 销售清单，记录已销售的宠物
    private int soldIndex; // 用于记录销售清单中宠物的数量

    public PetShop(String shopName, int cageSize) {
        this.shopName = shopName;
        cages = new Pet[cageSize];
        currentIndex = 0;
        soldPets = new Pet[100]; // 初始设置一个较大的长度，可根据实际情况调整
        soldIndex = 0;
    }

    // 进货宠物的方法
    public void buyPet(Pet pet) {
        if (currentIndex < cages.length) {
            cages[currentIndex] = pet;
            currentIndex++;
            System.out.println("成功购进宠物: " + pet.getBreed() + "，已放入宠物笼子。");
        } else {
            System.out.println("宠物笼子已满，无法购进新宠物。");
        }
    }

    // 销售宠物的方法
    public void sellPet(Pet pet) {
        boolean found = false;
        for (int i = 0; i < currentIndex; i++) {
            if (cages[i].getBreed().equals(pet.getBreed()) &&
                    cages[i].getColor().equals(pet.getColor()) &&
                    cages[i].getPrice() == pet.getPrice()) {
                // 将售出的宠物添加到销售清单
                soldPets[soldIndex] = pet;
                soldIndex++;
                // 移除笼子中的宠物
                System.arraycopy(cages, i + 1, cages, i, currentIndex - i - 1);
                currentIndex--;
                found = true;
                System.out.println("成功售出宠物: " + pet.getBreed() + "。");
                break;
            }
        }
        if (!found) {
            System.out.println("未找到匹配的宠物，无法销售。");
        }
    }

    // 清点宠物库存方法
    public void checkInventory() {
        System.out.println("宠物商店库存清单:");
        for (int i = 0; i < currentIndex; i++) {
            Pet pet = cages[i];
            System.out.println("品种: " + pet.getBreed() + ", 颜色: " + pet.getColor() + ", 进货价格: " + pet.getPrice());
        }
    }

    // 销售统计和盈利情况方法
    public void salesStatisticsAndProfit() {
        double totalProfit = 0;
        System.out.println("已销售宠物清单及盈利情况:");
        for (int i = 0; i < soldIndex; i++) {
            Pet pet = soldPets[i];
            System.out.println("品种: " + pet.getBreed() + ", 颜色: " + pet.getColor() + ", 进货价格: " + pet.getPrice() + ", 销售价格: " + pet.getPrice());
            totalProfit += pet.getPrice();
        }
        System.out.println("总利润: " + totalProfit);
    }
}

